package com.tedu.ivos.dict.controller;

import com.tedu.ivos.base.response.JsonResult;
import com.tedu.ivos.dict.pojo.dto.DictQuery;
import com.tedu.ivos.dict.pojo.dto.DictSaveParam;
import com.tedu.ivos.dict.pojo.vo.DictVO;
import com.tedu.ivos.dict.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(tags = "字典管理")
@RequestMapping("/v1/dict")
public class DictController {
    @Autowired
    DictService dictService;
    @ApiOperation(value = "查询字典数据功能")
    @GetMapping("/select")
    public JsonResult select(DictQuery dictQuery){
        log.debug("查询字典数据，参数：{}", dictQuery);
        List<DictVO> list =dictService.selectDict(dictQuery);
        return JsonResult.ok(list);
    }

    @ApiOperation(value = "保存(新增，修改)字典数据功能")
    @PostMapping("/save")
    public JsonResult saveDict(DictSaveParam dictSaveParam){
        log.debug("保存字典数据，参数：{}", dictSaveParam);
        dictService.saveDict(dictSaveParam);
        return JsonResult.ok();
    }
    @ApiOperation(value = "删除字典数据功能")
    @PostMapping("/delete/{id}")
    public JsonResult deleteDict(@PathVariable Long id){
        log.debug("删除字典数据，参数：{}", id);
        dictService.deleteDict(id);
        return JsonResult.ok();
    }


}
